package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.ParamItemService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/1
 */
@RestController
@RequestMapping("/param/item")
public class ParamItemController {

    @Resource
    private ParamItemService paramItemService;

    @PostMapping("/add")
    public ResponseData addParamItem(@RequestBody JSONObject param, @IRequestToken String token) {
        paramItemService.addParamItem(param);
        return ResponseData.success();
    }

    @GetMapping("/listAll")
    public ResponseData listAllParamItem(@IRequestToken String token) {
        return ResponseData.success(paramItemService.listAllParamItem());
    }

    @GetMapping("/detail")
    public ResponseData detail(@RequestParam(value = "paramItemId") Integer paramItemId, @IRequestToken String token) {
        return ResponseData.success(paramItemService.getParamItemDetail(paramItemId));
    }

    @GetMapping("/del")
    public ResponseData del(@IRequestParam JSONObject param, @IRequestToken String token) {
        paramItemService.deleteParamItem(param);
        return ResponseData.success();
    }

    @PostMapping("modify")
    public ResponseData modify(@RequestBody JSONObject param, @IRequestToken String token) {
        paramItemService.modifyParamItem(param);
        return ResponseData.success();
    }
}
